home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / units / PathList.pas < prev    next >
Pascal/Delphi Source File  |  1994-12-20  |  2KB  |  95 lines

  1. Unit PathList;
  2.  
  3. INTERFACE
  4. Uses Exec, AmigaDos;
  5.  
  6. Type
  7.     pPathList  = ^tPathList;
  8.     tPathList  = Record
  9.         NextPath,
  10.         PathLock : BPTR;
  11.     End;
  12.     
  13. Procedure InitPathList(VAR pl : pPathList);
  14. Procedure CopyPathList(src : pPathList; VAR dest : pPathList);
  15. Procedure FreePathList(VAR pl : pPathList);
  16.     
  17. IMPLEMENTATION    
  18.  
  19. Procedure InitPathList;
  20.  
  21. Var
  22.     cli    : pCommandLineInterface;
  23.     dummy  : pPathList;
  24.     wbproc : pProcess;
  25.     tn     : String;
  26.     
  27. Begin    
  28.     { get pointer to a path }
  29.     pl := NIL;
  30.     dummy := NIL;
  31.     wbproc := NIL;
  32.     if (pProcess(ThisTask)^.pr_Task.tc_Node.ln_Type <> NT_PROCESS) or
  33.            (BADDR(pProcess(ThisTask)^.pr_CLI) = NIL) then begin
  34.         { we have been run from Wb, copy WB pathlist }
  35.         tn := 'Workbench'#0;
  36.         wbproc := pProcess(FindTask(@tn[1]));
  37.         { make sure it is a process }
  38.         if wbproc^.pr_Task.tc_Node.ln_Type = NT_PROCESS then begin
  39.             cli := BADDR(wbproc^.pr_CLI);
  40.             { check we are a cli }
  41.             If cli <> NIL then begin
  42.                 { copy the path list }
  43.                 CopyPathList(pPathList(BADDR(cli^.cli_CommandDir)),pl);
  44.             End;
  45.         End;
  46.     End;
  47. End;
  48.  
  49.  
  50. { copy a path list }
  51. Procedure CopyPathList;
  52.  
  53. Var
  54.     pl, pl2 : pPathList;
  55.     
  56. Begin
  57.     dest := NIL;
  58.     pl2 := dest;
  59.     While src <> NIL do begin
  60.         pl := AllocVec(Sizeof(tPathList),MEMF_CLEAR);
  61.         If pl <> NIL then begin
  62.             pl^.PathLock := DupLock(src^.PathLock);
  63.             if pl2 = NIL then begin
  64.                 pl2 := pl;
  65.                 dest := pl2;
  66.             end else begin
  67.                 pl2^.NextPath := MKBADDR(pl);
  68.                 pl2 := pl;
  69.             End;
  70.             pl := NIL;
  71.         End;
  72.         src := BADDR(src^.NextPath);
  73.     End;
  74. End;
  75.  
  76.  
  77. { Free a path list }
  78. Procedure FreePathList;
  79.  
  80. Var
  81.     pla : pPathList;
  82.     
  83. Begin
  84.     if pl <> NIL then begin
  85.         Repeat 
  86.             UnLock(pl^.PathLock);
  87.             pla := BADDR(pl^.NextPath);
  88.             FreeVec(pl);
  89.             pl := pla;
  90.         Until pl = NIL;
  91.     End;
  92. End;
  93.  
  94. End.
  95.